package program.Junction;

import Exceptions.IllegalCoordinateException;
import Exceptions.ShootException;
import program.Atom;
import program.SExprList;
import program.SExpression;
import program.Condition.Condition;
import roborally.Robot;

/**
 * A class representing the OR junction.
 * 
 * @author Jef Keijers/Bachelor of Science: Informatics
 * @version 1.0
 */
public class Or extends Condition {
	/** This constructor instanstiate a new OR instance and sets the conditions to the given conditions.
	 * @param condition1
	 * @param condition2
	 */
	public Or(Condition condition1,Condition condition2) {
		this.condition1=condition1;
		this.condition2=condition2;
	}
	
	/**
	 * Returns true if one of the called methods returns true.
	 */
	@Override
	public boolean execute(Robot robot) throws ShootException, IllegalCoordinateException {
		return ((condition1.execute(robot)) || (condition2.execute(robot)));
	}

	/**
	 * Returns the SExpression representation of the OR junction.
	 */
	@Override
	public SExpression toSExpression() {
		SExprList sexpr = new SExprList();
		sexpr.add(new Atom("or"));
		sexpr.add(condition1.toSExpression());
		sexpr.add(condition2.toSExpression());
		return sexpr;
	}
	
	/**
	 * Instance variable representing condition 1 of the OR junction.
	 */
	private Condition condition1;
	
	/**
	 * Instance variable representing condition 2 of the OR junction.
	 */
	private Condition condition2;
}
